package lesson_three;

import org.junit.jupiter.api.*;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class TestSort {

    @BeforeAll
    public static void beforeAll() {
        System.out.println("开始测试所有程序");
    }

    @AfterAll
    public static void afterAll() {
        System.out.println("所有程序测试完成");
    }

    @BeforeEach
    public void beforeEach() {
        System.out.println("开始测试当前程序");
    }

    @AfterEach
    public void afterEach() {
        System.out.println("当前程序测试完成");
    }

    @Test
    @DisplayName("测试排序字符串")
    public void testSort() {
        String[] input = {"i", "have", "an", "egg"};
        String[] expected = {"an", "egg", "have", "i"};
        Sort.sort(input);
        assertArrayEquals(expected, input);
    }

    @Test
    @DisplayName("测试最小的字符串")
    public void testFindSmallest() {
        String[] input = {"peach", "watermelon", "egg", "apple", "bear"};
        String expected = "apple";


        int num = Sort.findSmallest(input, 2);
        String actual = input[num];
        assertEquals(expected, actual);
    }

    @Test
    @DisplayName("测试交换字符串")
    public void testSwap() {
        String[] input = {"i", "have", "an", "egg"};
        int a = 0;
        int b = 2;
        String[] expected = {"an", "have", "i", "egg"};
        Sort.swap(input, a, b);
        assertArrayEquals(expected, input);
    }

}
